const Router = require('koa-router');
let router = new Router();
const mongoose = require('mongoose');

router.get('/registUser', async (ctx) => {
  // get请求ctx.request.query(格式化) queryString(未格式化)
  // post请求ctx.request.body
  // 获取model
  const User = mongoose.model('User');

  // 接收请求
  let newUser = new User(ctx.request.query);
  await newUser
    .save()
    .then(() => {
      ctx.body = {
        code: 200,
        message: '注册成功',
      };
    })
    .catch((err) => {
      ctx.body = {
        code: 500,
        message: err,
      };
    });
});

module.exports = router;
